package com.banksoft.admin.service.impl;

import com.banksoft.admin.dao.NoticeDao;
import com.banksoft.admin.entity.Notice;
import com.banksoft.admin.service.NoticeService;
import com.banksoft.front.bean.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/14.
 */
@Service
public class NoticeServiceImpl implements NoticeService{

    @Autowired
    NoticeDao noticeDao;

    @Override
    public List<Notice> loadNotices(int size) {
        return this.noticeDao.loadNotices(size);
    }

    @Override
    public Page listByPage(int pageNo, int defaultSize) {
        if(pageNo<1)
            pageNo = 1;
        int start = (pageNo-1)*defaultSize;
        Map map = new HashMap();
        map.put("start",start);
        map.put("size",defaultSize);

        List<Notice> list = this.noticeDao.listForPage(map);
        int total = this.noticeDao.countForPage(map);

        return new Page(pageNo,total,list);
    }
}
